home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / symeval.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-18  |  10.4 KB  |  266 lines

  1. /* Definitions of symbol-value forwarding for XEmacs Lisp interpreter.
  2.    Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of XEmacs.
  5.  
  6. XEmacs is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the
  8. Free Software Foundation; either version 2, or (at your option) any
  9. later version.
  10.  
  11. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with XEmacs; see the file COPYING.  If not, write to the Free
  18. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Synched up with: Not in FSF. */
  21.  
  22. /* Fsymbol_value checks whether XSYMBOL (sym)->value is one of these,
  23.  *  and does weird magic stuff if so */
  24.  
  25. #ifndef _XEMACS_SYMEVAL_H_
  26. #define _XEMACS_SYMEVAL_H_
  27.  
  28. struct symbol_value_magic
  29. {
  30.   struct lcrecord_header lcheader;
  31.   enum
  32.     {
  33.       /* The following tags use the 'symbol_value_forward' structure
  34.      and are strictly for variables DEFVARed on the C level. */
  35.       SYMVAL_FIXNUM_FORWARD,           /* Forward C "int" */
  36.       SYMVAL_BOOLEAN_FORWARD,          /* Forward C boolean ("int") */
  37.       SYMVAL_OBJECT_FORWARD,           /* Forward C Lisp_Object */
  38.       SYMVAL_DEFAULT_BUFFER_FORWARD,   /* Forward Lisp_Object into Vbuffer_defaults */
  39.       SYMVAL_CURRENT_BUFFER_FORWARD,   /* Forward Lisp_Object into current_buffer */
  40.       /*SYMVAL_SOME_BUFFER_FORWARD,       Either current_buffer or buffer_defaults */
  41.       SYMVAL_UNBOUND_MARKER,           /* Only Qunbound actually has this tag */
  42.       SYMVAL_CONST_SPECIFIER_FORWARD,  /* Forward C Lisp_Object (a specifier
  43.                       where you can't change the
  44.                       actual specifier object assigned
  45.                       to the variable) */
  46.  
  47.       /* The following tags use the 'symbol_value_buffer_local' structure */
  48.       SYMVAL_BUFFER_LOCAL,             /* make-variable-buffer-local */
  49.       SYMVAL_SOME_BUFFER_LOCAL,        /* make-local-variable */
  50.  
  51.       /* The following tag uses the 'symbol_value_varalias' structure */
  52.       SYMVAL_VARALIAS               /* defvaralias */
  53.  
  54. #if 0
  55.       /* NYI */
  56.       SYMVAL_CONSTANT_SYMBOL,           /* Self-evaluating symbol */
  57.       /* NYI */
  58.       SYMVAL_LISP_MAGIC,           /* Forward to lisp callbacks */
  59. #endif
  60.     } type;
  61. };
  62. #define SYMBOL_VALUE_MAGIC_P(x)                \
  63.   (LRECORDP (x)                        \
  64.    && (XRECORD_LHEADER (x)->implementation->printer    \
  65.        == print_symbol_value_magic))
  66. #define XSYMBOL_VALUE_MAGIC_TYPE(v) \
  67.     (((struct symbol_value_magic *) XPNTR (v))->type)
  68. #define XSETSYMBOL_VALUE_MAGIC(s, p) XSETOBJ (s, Lisp_Record, p)
  69. extern void print_symbol_value_magic (Lisp_Object, Lisp_Object, int);
  70.  
  71. /********** The various different symbol-value-magic types ***********/
  72.  
  73. /* 1. symbol-value-forward */
  74.  
  75. /* This type of symbol-value-magic is used for variables declared
  76.    DEFVAR_LISP, DEFVAR_INT, DEFVAR_BOOL, DEFVAR_BUFFER_LOCAL,
  77.    DEFVAR_BUFFER_DEFAULTS, DEFVAR_SPECIFIER, and for Qunbound.
  78.  
  79.    Note that some of these types of variables can be made buffer-local.
  80.    Then, the symbol's value field contains a symbol-value-buffer-local,
  81.    whose CURRENT-VALUE field then contains a symbol-value-forward.
  82.  */
  83.      
  84. extern CONST_IF_NOT_DEBUG struct lrecord_implementation
  85.   lrecord_symbol_value_forward[];
  86. struct symbol_value_forward
  87. {
  88.   struct symbol_value_magic magic;
  89.   /* void *forward; -- use magic.lcheader.next instead */
  90.   /* Function controlling magic behavior of this forward variable.
  91.  
  92.      SYM is the symbol being operated on (read, set, etc.);
  93.  
  94.      VAL is either the value to set or the value to be returned.
  95.  
  96.      BUF is the buffer that the value is read in or set in.
  97.        A value of 0 means that the current buffer and possibly
  98.        other buffers are being set. (This value will never be
  99.        passed for built-in buffer-local variables such as
  100.        `truncate-lines'.) (Currently, a value of 0 is always
  101.        passed for DEFVAR_INT, DEFVAR_LISP, and DEFVAR_BOOL
  102.        variables; the code isn't smart enough to figure out
  103.        what buffers besides the current buffer are being
  104.        affected.  Because the magic function is called
  105.        before the value is changed, it's not that easy
  106.        to determine which buffers are getting changed.
  107.        #### If this information is important, let me know
  108.        and I will look into providing it.)
  109.  
  110.      FLAGS gives more information about the operation being
  111.        performed.
  112.  
  113.      The return value indicates what the magic function actually
  114.        did.
  115.  
  116.      Currently FLAGS and the return value are not used.  This
  117.      function is only called when the value of a forward variable
  118.      is about to be changed.  Note that this can occur explicitly
  119.      through a call to `set', `setq', `set-default', or `setq-default',
  120.      or implicitly by the current buffer being changed.
  121.  
  122.      */
  123.      
  124.   int (*magicfun) (Lisp_Object sym, Lisp_Object *val, struct buffer *buf,
  125.            int flags);
  126. };
  127. #define XSYMBOL_VALUE_FORWARD(v) \
  128.     ((CONST struct symbol_value_forward *) XPNTR(v))
  129. #define symbol_value_forward_forward(m) ((void *)((m)->magic.lcheader.next))
  130. #define symbol_value_forward_magicfun(m) ((m)->magicfun)
  131.  
  132. /* 2. symbol-value-buffer-local */
  133.  
  134. extern CONST_IF_NOT_DEBUG struct lrecord_implementation
  135.   lrecord_symbol_value_buffer_local[];
  136. struct symbol_value_buffer_local
  137. {
  138.   struct symbol_value_magic magic;
  139.   /* Used in a symbol value cell when the symbol's value is per-buffer.
  140.    * 
  141.    * CURRENT-BUFFER is the last buffer for which this symbol's value was
  142.    * made up to date.
  143.    * 
  144.    * CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
  145.    * buffer_local_var_alist, that being the element whose car
  146.    * is this variable.
  147.    * Or it can be NIL if BUFFER does not have an element in its
  148.    *  alist for this variable (that is, if BUFFER sees the default
  149.    *  value of this variable).
  150.    * 
  151.    * If we want to examine or set the value and BUFFER is current,
  152.    * we just examine or set REALVALUE.
  153.    * If BUFFER is not current, we store the current REALVALUE value into
  154.    * CURRENT-ALIST-ELEMENT, then find the appropriate alist element for
  155.    * the buffer now current and set up CURRENT-ALIST-ELEMENT.
  156.    * Then we set REALVALUE out of that element, and store into BUFFER.
  157.    * 
  158.    * If we are setting the variable and the current buffer does not have
  159.    * an alist entry for this variable, an alist entry is created.
  160.    * 
  161.    * Note that CURRENT-VALUE (but not DEFAULT-VALUE) can be a
  162.    * forwarding pointer.  Each time it is examined or set, 
  163.    * forwarding must be done.
  164.    */
  165.   Lisp_Object default_value;
  166.   Lisp_Object current_value;
  167.   Lisp_Object current_buffer;
  168.   Lisp_Object current_alist_element;
  169. };
  170. #define XSYMBOL_VALUE_BUFFER_LOCAL(v) \
  171.     ((struct symbol_value_buffer_local *) XPNTR(v))
  172.  
  173.  
  174. /* 3. symbol-value-varalias */
  175.  
  176. extern CONST_IF_NOT_DEBUG struct lrecord_implementation
  177.   lrecord_symbol_value_varalias[];
  178. struct symbol_value_varalias
  179. {
  180.   struct symbol_value_magic magic;
  181.   Lisp_Object aliasee;
  182.   Lisp_Object shadowed;
  183. };
  184. #define XSYMBOL_VALUE_VARALIAS(v)            \
  185.     ((struct symbol_value_varalias *) XPNTR(v))
  186. #define SYMBOL_VALUE_VARALIAS_P(v)            \
  187.   (SYMBOL_VALUE_MAGIC_P (v) &&                \
  188.    XSYMBOL_VALUE_MAGIC_TYPE (v) == SYMVAL_VARALIAS)
  189. #define symbol_value_varalias_aliasee(m) ((m)->aliasee)
  190. #define symbol_value_varalias_shadowed(m) ((m)->shadowed)
  191.  
  192. /* defsubr (Sname);
  193.  is how we define the symbol for function `name' at start-up time. */
  194. extern void defsubr (struct Lisp_Subr *);
  195.  
  196. extern void defsymbol (Lisp_Object *location, CONST char *name);
  197.  
  198. extern void defkeyword (Lisp_Object *location, CONST char *name);
  199.  
  200. extern void deferror (Lisp_Object *symbol, CONST char *name,
  201.               CONST char *message, int error_type);
  202.  
  203. /* Macros we use to define forwarded Lisp variables.
  204.    These are used in the syms_of_FILENAME functions.  */
  205.  
  206. extern void defvar_mumble (CONST char *names,
  207.                            CONST void *magic, int sizeof_magic);
  208.  
  209. #define DEFVAR_HEADER(lname, c_location, forward_type)              \
  210.   static CONST struct symbol_value_forward I_hate_C              \
  211.    = { { { { lrecord_symbol_value_forward }, (void *) (c_location), 69 }, \
  212.          forward_type }, 0 };                          \
  213.   defvar_mumble ((lname), &I_hate_C, sizeof (I_hate_C))
  214.  
  215. #define DEFVAR_MAGIC_HEADER(lname, c_location, forward_type, magicfun)      \
  216.   static CONST struct symbol_value_forward I_hate_C              \
  217.    = { { { { lrecord_symbol_value_forward }, (void *) (c_location), 69 }, \
  218.          forward_type }, magicfun };                      \
  219.   defvar_mumble ((lname), &I_hate_C, sizeof (I_hate_C))
  220.  
  221. #define DEFVARLISP(lname, c_location, doc)            \
  222.  do { DEFVAR_HEADER (lname, c_location, SYMVAL_OBJECT_FORWARD);    \
  223.       staticpro (c_location);                    \
  224.  } while (0)
  225. #define DEFVARSPECIFIER(lname, c_location, doc)                 \
  226.  do { DEFVAR_HEADER (lname, c_location, SYMVAL_CONST_SPECIFIER_FORWARD); \
  227.       staticpro (c_location);                         \
  228.  } while (0)
  229. #define DEFVARINT(lname, c_location, doc)            \
  230.  do { DEFVAR_HEADER (lname, c_location, SYMVAL_FIXNUM_FORWARD);    \
  231.  } while (0)
  232. #define DEFVARBOOL(lname, c_location, doc)            \
  233.  do { DEFVAR_HEADER (lname, c_location, SYMVAL_BOOLEAN_FORWARD);\
  234.  } while (0)
  235.  
  236. #define DEFVARLISP_MAGIC(lname, c_location, doc, magicfun)    \
  237.  do { DEFVAR_MAGIC_HEADER (lname, c_location,            \
  238.       SYMVAL_OBJECT_FORWARD, magicfun);                \
  239.       staticpro (c_location);                    \
  240.  } while (0)
  241. #define DEFVARINT_MAGIC(lname, c_location, doc, magicfun)    \
  242.  do { DEFVAR_MAGIC_HEADER (lname, c_location,            \
  243.       SYMVAL_FIXNUM_FORWARD, magicfun);                \
  244.  } while (0)
  245. #define DEFVARBOOL_MAGIC(lname, c_location, doc, magicfun)    \
  246.  do { DEFVAR_MAGIC_HEADER (lname, c_location,            \
  247.       SYMVAL_BOOLEAN_FORWARD, magicfun);            \
  248.  } while (0)
  249.  
  250. /* These discard their DOC arg because it is snarfed by make-docfile
  251.  *  and stored in an external file. */
  252. #define DEFVAR_LISP(lname, c_location, doc) DEFVARLISP (lname, c_location, 0)
  253. #define DEFVAR_SPECIFIER(lname, c_location, doc) \
  254.   DEFVARSPECIFIER (lname, c_location, 0)
  255. #define DEFVAR_BOOL(lname, c_location, doc) DEFVARBOOL (lname, c_location, 0)
  256. #define DEFVAR_INT(lname, c_location, doc) DEFVARINT (lname, c_location, 0)
  257.  
  258. #define DEFVAR_LISP_MAGIC(lname, c_location, doc, magicfun) \
  259.   DEFVARLISP_MAGIC (lname, c_location, 0, magicfun)
  260. #define DEFVAR_BOOL_MAGIC(lname, c_location, doc, magicfun) \
  261.   DEFVARBOOL_MAGIC (lname, c_location, 0, magicfun)
  262. #define DEFVAR_INT_MAGIC(lname, c_location, doc, magicfun) \
  263.   DEFVARINT_MAGIC (lname, c_location, 0, magicfun)
  264.  
  265. #endif /* _XEMACS_SYMEVAL_H_ */
  266.